package ie.lawlor.amvc.example.explorer.orinoco;
import ie.lawlor.amvc.event.Event;
import ie.lawlor.amvc.event.ExceptionPayload;
import ie.lawlor.amvc.swing.JFrameView;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.BoxLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;






/**
* This code was generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* *************************************
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED
* for this machine, so Jigloo or this code cannot be used legally
* for any corporate or commercial purpose.
* *************************************
*/
/**
 * @author blawlor
 *
 */
public class OrinocoView extends JFrameView {
  private static Dimension ACTIVITY_MIN_DIMENSION = new Dimension(200, 40);
  private static Dimension LIST_MIN_DIMENSION = new Dimension(0, 40);
	private static Dimension LIST_MAX_DIMENSION = new Dimension(0, 4000);
	private static Dimension LIST_PREFERRED_DIMENSION = new Dimension(0, 300);
	private static Dimension DETAILS_MIN_DIMENSION = new Dimension(0, 40);
	private static Dimension DETAILS_MAX_DIMENSION = new Dimension(0, 2000);
	private static Dimension DETAILS_PREFERRED_DIMENSION = new Dimension(0, 200);

	public OrinocoView(){
		this("noName");
	}
	public OrinocoView(String name){
		super(name);
		folderPanel = new JPanel();
    activityPanel = new JPanel();
    activityPanel.setLayout(new BoxLayout(activityPanel, BoxLayout.Y_AXIS));
//    activityPanel.setMinimumSize(ACTIVITY_MIN_DIMENSION);
		activityPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    activityPanel.add(activityPane);
//    activityPane.setMinimumSize(ACTIVITY_MIN_DIMENSION);
//    activityPanel.add(activityPane);
		listPanel = new JPanel();
//    JScrollPane listScrollPane = new JScrollPane();
//    listScrollPane.add(listPanel);
//		listPanel.setLayout(new BorderLayout());
//		listPanel.setMinimumSize(LIST_MIN_DIMENSION);
//		listPanel.setMinimumSize(LIST_MAX_DIMENSION);
//		listPanel.setPreferredSize(LIST_PREFERRED_DIMENSION);
		detailPanel = new JPanel();
//    JScrollPane detailScrollPane = new JScrollPane();
//    detailScrollPane.add(detailPanel);
    activityPane.add(JSplitPane.TOP, listPanel);
    activityPane.add(JSplitPane.BOTTOM, detailPanel);
    activityPane.setResizeWeight(0.5);
//		detailPanel.setLayout(new BorderLayout());
//		detailPanel.setMinimumSize(DETAILS_MIN_DIMENSION);
//		detailPanel.setMaximumSize(DETAILS_MAX_DIMENSION);
//		detailPanel.setPreferredSize(DETAILS_PREFERRED_DIMENSION);
//		activityPane.add(JSplitPane.TOP, listPanel);
//		activityPane.add(JSplitPane.BOTTOM, detailPanel);
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
		getContentPane().add(folderPanel);	
    getContentPane().add(activityPanel);
    

    }
	
    public void doInitView(Event e){
      
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

      /* Center frame on the screen */
      Dimension frameSize = new Dimension();
      frameSize.height = screenSize.height - 200;
      frameSize.width = screenSize.width - 80;
      setLocation(40, 100);
      setSize(frameSize);
    }

    public Container getContainer(String viewName){
    	if (viewName == null){
    		System.out.println("Viewname is null");
    	} else if (viewName.equals(FOLDER_VIEW)){
    		return getFolderPanel();
		} else if (viewName.equals(LIST_VIEW)){
			return getListPanel();
		} else if (viewName.equals(DETAIL_VIEW)){
			return getDetailPanel();
    	} else {
			System.out.println("Viewname is unknown");    		
    	}
    	return null;
    }
    
	public void doException(Event e){
		ExceptionPayload payload = (ExceptionPayload)e.getPayload();
		String message = payload.message;
		Throwable t = payload.throwable;
		if (message == null) {
			message = t.getClass().toString();
		}
		JOptionPane.showMessageDialog(this,message);
	}
	
	private JPanel getFolderPanel(){
		return folderPanel;
	}
	
	private JPanel getListPanel(){
		return listPanel;
	}
	
	private JPanel getDetailPanel(){
		return detailPanel;
	}
	
	private JSplitPane mainPane = null;
	private JPanel folderPanel = null;
	private JSplitPane activityPane = null;
	private JPanel listPanel = null;
  private JPanel detailPanel = null;
  private JPanel activityPanel = null;
	public static final String LIST_VIEW = "list";
	public static final String DETAIL_VIEW = "detail";
    public static final String FOLDER_VIEW = "folder";
}
